import 'dart:convert';

// import 'package:cash4life/tools/EJ_Config.dart';
import 'package:dio/dio.dart';

import '../KaL_Config.dart';

class ALHttprequest {
  final dio = Dio();

  getAllKeralaLottoData() async {
    String url = KaL_Config.KaL_address;
    String URLStr = '$url/index.php/Api/keralaLotteryRawData';

    var data;
    try {
      final response = await dio.post(URLStr);

      /// 格式化接收到的数据
      data = jsonDecode(response.data);
    } catch (e) {
      data = {"status": 100, "code": 0, "message": "", "data": []};
    }

    return data;
  }

  getKeralaLotteryNextDranw() async {
    String url = KaL_Config.KaL_address;
    String URLStr = '$url/index.php/Api/keralaLotteryNextDraw';
    var data;
    try {
      final response = await dio.post(URLStr);

      /// 格式化接收到的数据
      data = jsonDecode(response.data);
    } catch (e) {
      data = {"status": 100, "code": 0, "message": "", "data": {}};
    }

    return data;
  }

  getCurrentDrawnDetail(String drawnCode) async {
    String url = KaL_Config.KaL_address;
    String URLStr =
        '$url/index.php/Api/keralaLotteryDrawDetails?drawcode=$drawnCode';
    var data;
    try {
      final response = await dio.post(URLStr);

      /// 格式化接收到的数据
      data = jsonDecode(response.data);
    } catch (e) {
      data = {"status": 100, "code": 0, "message": "", "data": {}};
    }

    return data;
  }

  //请求全部数据
  getData(int pageSize) async {
    String url = KaL_Config.KaL_address;
    String slug = KaL_Config.KaL_slug;
    String URLStr =
        '$url/index.php/Api/rawLottoData?lotto=$slug&pagesize=$pageSize';

    var data;
    try {
      final response = await dio.post(URLStr);

      /// 格式化接收到的数据
      data = jsonDecode(response.data);
    } catch (e) {
      data = {"status": 100, "code": 0, "message": "", "data": {}};
    }

    // var data = response.data;
    return data;
  }
}
